home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / license.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  3.8 KB  |  156 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. #include <windows.h>
  20. #include "resource.h"
  21. #include "oshelper.h"
  22.  
  23. // There are some truly lame people out there who would try to rip off
  24. // an open source program by hacking the binary!
  25.  
  26. #pragma optimize("as", on)
  27. extern const unsigned char fht_tab[];
  28.  
  29. typedef unsigned char byte;
  30.  
  31. class Licensor {
  32. public:
  33.     Licensor();
  34.     Licensor(HWND);
  35.  
  36.     static BOOL APIENTRY DProc( HWND hDlg, UINT message, UINT wParam, LONG lParam);
  37.     static void depack(HWND hDlg);
  38. } g_licensor;
  39.  
  40. // Wouldn't be fun without some good old-fashioned string expansion and LZ77 encoding.
  41.  
  42. void Licensor::depack(HWND hDlg) {
  43.     unsigned char depackbuf[15073], textbuf[18316];
  44.     HRSRC hRSRC;
  45.  
  46.     if (hRSRC = FindResource(NULL, (LPSTR)IDR_VIRUS, "STUFF")) {
  47.         HGLOBAL hGlobal;
  48.         if (hGlobal = LoadResource(NULL, hRSRC)) {
  49.             LPVOID lpData;
  50.  
  51.             if (lpData = LockResource(hGlobal)) {
  52.                 byte *s = (byte *)lpData;
  53.                 byte *t = depackbuf;
  54.                 int sum = 0;
  55.                 unsigned long code = 0;
  56.  
  57.                 while(sum != 0xfffff609) {
  58.                     if (!(code >> 24)) {
  59.                         code = *s++ | 0xff000000;
  60.                     }
  61.  
  62.                     if (code & 0x80) {
  63.                         sum += *t++ = *s++;
  64.                         sum = ~sum;
  65.                     } else {
  66.                         int off = *(unsigned short *)s;
  67.                         int count = (off>>12)+3;
  68.                         off &= 0xfff;
  69.                         s += 2;
  70.  
  71.                         do {
  72.                             sum += *t = t[off - 4096];
  73.                             sum = ~sum;
  74.                             ++t;
  75.                         } while(--count);
  76.                     }
  77.  
  78.                     code += code;
  79.                 }
  80.  
  81.                 s = depackbuf;
  82.                 t = textbuf;
  83.  
  84.                 while(t != textbuf + 18316) {
  85.                     if (*s >= 0xa0) {
  86.                         *t++ = ' ';
  87.                         *t++ = *s & 0x7f;
  88.                     } else if (*s >= 0x80)
  89.                         while((*s)-->=0x80)
  90.                             *t++ = ' ';
  91.                     else {
  92.                         if (*s == '\n')
  93.                             *t++ = '\r';
  94.                         *t++ = *s;
  95.                     }
  96.                     ++s;
  97.                 }
  98.                 *t = 0;
  99.  
  100.                 SendMessage(GetDlgItem(hDlg, IDC_LICENSE), WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), MAKELPARAM(TRUE, 0));
  101.                 SendMessage(GetDlgItem(hDlg, IDC_LICENSE), WM_SETTEXT, 0, (LPARAM)textbuf);
  102.                 FreeResource(hGlobal);
  103.                 return;
  104.             }
  105.             FreeResource(hGlobal);
  106.         }
  107.     }
  108.     EndDialog(hDlg, 0);
  109. }
  110.  
  111. BOOL APIENTRY Licensor::DProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  112.     switch (message)
  113.     {
  114.         case WM_INITDIALOG:
  115.             depack(hDlg);
  116.             return TRUE;
  117.  
  118.         case WM_COMMAND:
  119.             if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
  120.             {
  121.                 EndDialog(hDlg, 1);  
  122.                 return TRUE;
  123.             }
  124.             break;
  125.     }
  126.     return FALSE;
  127. }
  128.  
  129. Licensor::Licensor() {
  130.     char str[11];
  131.     int i;
  132.     DWORD dw;
  133.  
  134.     for(i=0; i<10; i++)
  135.         str[i] = fht_tab[i]^0xaa;
  136.     str[i] = 0;
  137.  
  138.     if (QueryConfigDword(NULL, str, &dw) && dw)
  139.         return;
  140.  
  141.     SetConfigDword(NULL, str, 1);
  142.     if (!DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_LICENSE), NULL, DProc))
  143.         throw new int('budv');
  144. }
  145.  
  146. Licensor::Licensor(HWND hwndParent) {
  147.  
  148.  
  149.     if (!DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_LICENSE), hwndParent, DProc))
  150.         throw new int('budv');
  151. }
  152.  
  153. extern void DisplayLicense(HWND hwndParent) {
  154.     Licensor l(hwndParent);
  155. }
  156.